<template>
  <a-modal
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-card style="margin-top: 10px" >
      <a-row v-for="it in this.qlist" style="border: 1px solid rgba(236,236,236,0.37);">
        <a-col :span="2" v-if="it.parendid==0">
          {{it.itemNum}}
          <span v-if="it.selectType ==1">(单选)</span>
          <span v-if="it.selectType ==2">多选</span>
        </a-col>
        <a-col :span="13" v-if="it.parendid==0">
            {{it.itemName}}
        </a-col>
        <a-col :span="6" v-if="it.parendid==0">
          <a-checkbox-group v-model="selectids"   >
            <a-checkbox
                    v-for="(item) in it.mapTemp.clist"
                    :key="item.id"
                    @change="radioClick"
                    :value="parseInt(item.id)">
              {{ item.itemName }}
            </a-checkbox>
          </a-checkbox-group>
        </a-col>
      </a-row>
    </a-card>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'

  export default {
    name: 'EvaQuestionGlid',
    components: {},
    data () {
      return {
        visible: false,
        confirmLoading: false,
          selectid:'',
          selectids:undefined,
          selectname:'',
        formInfo: {},
          dlist:[],
          qlist:[],
        url: {
          saveInfo: '/system/evaQuestion/save',
          getInfo: '/system/evaQuestion/getinfo'
        }
      }
    },
    created () {
    },
    methods: {
      show (record) {
        if (record) {
          getAction(this.url.getInfo, { 'id': record }).then(res => {
            this.$nextTick(() => {
                this.dlist = res.result.dlist
                this.qlist = res.result.qlist
            })
          })
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
          this.selectname=''
          this.selectid=''
          console.log(this.selectids)
          this.selectids.forEach((item, index) => {
              const selected = this.dlist.find(option => option.id === item);
              if (selected) {
                  this.selectname +=  selected.itemName+";";
                  this.selectid += selected.parendid + "-" + item+";"
              }
          });

          console.log(this.selectid)
          console.log(this.selectname)
          this.$emit('ok', this.selectid, this.selectname)
          this.visible = false
      },
        radioClick(val){
            // this.selectid = val.target.value
            // this.$forceUpdate()
            // console.log(this.selectids)
        },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
          this.qlist=[]
        this.visible = false
      }
    }
  }
</script>
